package com.ruoyi.manage.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.manage.domain.BmAddress;
import com.ruoyi.manage.service.BmAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 店铺信息Controller
 *
 * @author ruoyi
 * @date 2022-11-09
 */
@RestController
@RequestMapping("/address")
public class BmAddressController extends BaseController
{
    @Autowired
    private BmAddressService bmAddressService;

    /**
     * 查询店铺信息列表
     */
//    @RequiresPermissions("manage:address:list")
    @GetMapping("/list")
    public TableDataInfo list(BmAddress bmAddress)
    {
        startPage();
        List<BmAddress> list = bmAddressService.selectBmAddressList(bmAddress);
        return getDataTable(list);
    }

    /**
     * 导出店铺信息列表
     */
//    @RequiresPermissions("manage:address:export")
    @Log(title = "店铺信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmAddress bmAddress)
    {
        List<BmAddress> list = bmAddressService.selectBmAddressList(bmAddress);
        ExcelUtil<BmAddress> util = new ExcelUtil<BmAddress>(BmAddress.class);
        util.exportExcel(response, list, "店铺信息数据");
    }

    /**
     * 获取店铺信息详细信息
     */
//    @RequiresPermissions("manage:address:query")
    @GetMapping(value = "/{addid}")
    public AjaxResult getInfo(@PathVariable("addid") Long addid)
    {
        return AjaxResult.success(bmAddressService.selectBmAddressByAddid(addid));
    }

    /**
     * 新增店铺信息
     */
//    @RequiresPermissions("manage:address:add")
    @Log(title = "店铺信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmAddress bmAddress)
    {
        return toAjax(bmAddressService.insertBmAddress(bmAddress));
    }

    /**
     * 修改店铺信息
     */
//    @RequiresPermissions("manage:address:edit")
    @Log(title = "店铺信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmAddress bmAddress)
    {
        return toAjax(bmAddressService.updateBmAddress(bmAddress));
    }

    /**
     * 删除店铺信息
     */
//    @RequiresPermissions("manage:address:remove")
    @Log(title = "店铺信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{addids}")
    public AjaxResult remove(@PathVariable Long[] addids)
    {
        return toAjax(bmAddressService.deleteBmAddressByAddids(addids));
    }
}

